<?php
/**
 * Copyright (c) 2006, PORTALIER Julien
 * 
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @copyright    Copyright (c) 2006, Julien PORTALIER
 * @link         http://code.google.com/p/feather-cm
 * @license      http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

abstract class Aclnode extends ActiveRecord
{
	protected $key;
	public    $prefix;
	
	function resolveID($resource)
	{
		if (empty($this->key))
			$this->key = Inflector::underscore($this->name);
		
		$this->id = null;
		$this->conditions(array("{$this->name}.{$this->key}" => $this->prefix.$resource));
		return $this->field("{$this->name}.id");
	}
	
	// admin
	
	function create($data)
	{
		if (empty($this->key))
			$this->key = Inflector::underscore($this->name);
		
		if (!is_array($data))
			$data = array($this->key => $this->prefix.$data);
		
		$this->__setData(&$data);
		$this->__save('insert');
		return $this->id;
	}
	
	function destroy($res)
	{
		$this->delete($this->resolveID($res), false);
	}
	
	// overrides
	
	function __get($name)
	{
		$this->$name = new $name;
		return $this->$name;
	}
}

class Aro extends Aclnode
{
    public $hasMany = array('Role');
}

class Aco extends Aclnode
{
    public $hasMany = array('Role');
}
?>
